use std::collections::*;
use std::io::*;

fn main() {
    let stdin = stdin();
    let mut lines = stdin.lock().lines().map(|line| line.unwrap());

    let v: Vec<u128> = lines
        .next()
        .unwrap()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
    let (_n, k) = (v[0], v[1]);

    let v: Vec<u128> = lines
        .next()
        .unwrap()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();

    let mut max_heap = BinaryHeap::new();
    for (idx, num) in v.iter().enumerate() {
        max_heap.push((num, idx));
    }
    let mut sum = 0;

    let mut cnt = vec![1; v.len() / k as usize];

    while !max_heap.is_empty() {
        let (num, idx) = max_heap.pop().unwrap();
        let mut flag = false;
        for i in (1..=(idx / k as usize)).rev() {
            if cnt[i - 1] == 1 {
                cnt[i - 1] = 0;
                flag = true;
                break;
            }
        }
        if !flag {
            sum += num;
        }
    }

    println!("{}", sum);
    //anbvvvvvvvv
}
